package Internet.Program.UDP;


import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @Author: Jason
 * @ClassName: UDPServerDemo1
 * @Description: UDP
 * @Package：Internet.Program.UDP
 * @Project：javaDemo
 * @name：UDPServerDemo1
 * @Filename：UDPServerDemo1
 **/

//还是要等待客户端的连接！
public class UDPServerDemo1 {
    public static void main(String[] args) throws Exception {
        //开放端口
        DatagramSocket socket = new DatagramSocket(9090);
        //接受数据包
        byte[] bytes = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes,0,bytes.length);

        socket.receive(packet);//阻塞接收
        System.out.println(packet.getAddress().getHostAddress());
        System.out.println(new String(packet.getData(),0,packet.getLength()));

        //关闭连接
        socket.close();
    }

}
